package com.tange.ai.iot.client.gnssa.utils;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;

import com.berwin.cocoadialog.CocoaDialog;
import com.berwin.cocoadialog.CocoaDialogAction;
import com.berwin.cocoadialog.CocoaDialogActionStyle;
import com.berwin.cocoadialog.CocoaDialogStyle;

/**
 * 说明：
 * Created by jjs on 2018/12/25
 */
public class DialogUtil {

    public static CocoaDialog alert(@NonNull Context context, @StringRes int titleRes,
                                    @StringRes int messageRes, @StringRes int buttonTitleRes) {
        return alert(context, titleRes, messageRes, buttonTitleRes, 0, null, null);
    }

    public static CocoaDialog alert(@NonNull Context context, @StringRes int titleRes,
                                    @StringRes int messageRes, @StringRes int buttonTitleRes,
                                    CocoaDialogAction.OnClickListener buttonClickListener) {
        return alert(context, titleRes, messageRes, buttonTitleRes, 0, buttonClickListener, null);
    }

    public static CocoaDialog alert(@NonNull Context context, @StringRes int titleRes,
                                    @StringRes int messageRes, boolean cancelable, @StringRes int buttonTitleRes,
                                    CocoaDialogAction.OnClickListener buttonClickListener) {
        return alert(context, titleRes, messageRes, cancelable, buttonTitleRes, 0, buttonClickListener, null);
    }

    public static CocoaDialog alert(
            @NonNull Context context,
            @StringRes int titleRes, @StringRes int messageRes,
            @StringRes int button1TitleRes, @StringRes int button2TitleRes,
            CocoaDialogAction.OnClickListener button1ClickListener,
            CocoaDialogAction.OnClickListener button2ClickListener) {
        CocoaDialog.Builder builder = new CocoaDialog.Builder(context, CocoaDialogStyle.alert);
        builder.setTitle(titleRes);
        builder.setMessage(messageRes);
        if (button1TitleRes != 0) {
            builder.addAction(new CocoaDialogAction(
                    context.getString(button1TitleRes),
                    CocoaDialogActionStyle.normal,
                    button1ClickListener));
        }
        if (button2TitleRes != 0) {
            builder.addAction(new CocoaDialogAction(
                    context.getString(button2TitleRes),
                    CocoaDialogActionStyle.normal,
                    button2ClickListener));
        }
        return builder.build();
    }

    public static CocoaDialog alert(
            @NonNull Context context,
            @StringRes int titleRes, @StringRes int messageRes,
            boolean cancelable,
            @StringRes int button1TitleRes, @StringRes int button2TitleRes,
            CocoaDialogAction.OnClickListener button1ClickListener,
            CocoaDialogAction.OnClickListener button2ClickListener) {
        CocoaDialog.Builder builder = new CocoaDialog.Builder(context, CocoaDialogStyle.alert);
        builder.setTitle(titleRes);
        builder.setMessage(messageRes);
        builder.setCancelable(cancelable);
        if (button1TitleRes != 0) {
            builder.addAction(new CocoaDialogAction(
                    context.getString(button1TitleRes),
                    CocoaDialogActionStyle.normal,
                    button1ClickListener));
        }
        if (button2TitleRes != 0) {
            builder.addAction(new CocoaDialogAction(
                    context.getString(button2TitleRes),
                    CocoaDialogActionStyle.normal,
                    button2ClickListener));
        }
        return builder.build();
    }

    public static CocoaDialog alert(
            @NonNull Context context,
            String titleRes, String messageRes,
            String button1TitleRes, String button2TitleRes,
            CocoaDialogAction.OnClickListener button1ClickListener,
            CocoaDialogAction.OnClickListener button2ClickListener) {
        CocoaDialog.Builder builder = new CocoaDialog.Builder(context, CocoaDialogStyle.alert);
        builder.setTitle(titleRes);
        builder.setMessage(messageRes);
        builder.addAction(new CocoaDialogAction(
                button1TitleRes,
                CocoaDialogActionStyle.normal,
                button1ClickListener));
        builder.addAction(new CocoaDialogAction(
                button2TitleRes,
                CocoaDialogActionStyle.normal,
                button2ClickListener));
        return builder.build();
    }

    public static CocoaDialog alert(
            @NonNull Context context,
            String titleRes, String messageRes,
            boolean cancelable,
            String button1TitleRes, String button2TitleRes,
            CocoaDialogAction.OnClickListener button1ClickListener,
            CocoaDialogAction.OnClickListener button2ClickListener) {
        CocoaDialog.Builder builder = new CocoaDialog.Builder(context, CocoaDialogStyle.alert);
        builder.setTitle(titleRes)
                .setMessage(messageRes)
                .setCancelable(cancelable)
                .addAction(new CocoaDialogAction(
                        button1TitleRes,
                        CocoaDialogActionStyle.normal,
                        button1ClickListener))
                .addAction(new CocoaDialogAction(
                        button2TitleRes,
                        CocoaDialogActionStyle.normal,
                        button2ClickListener));
        return builder.build();
    }

    public static CocoaDialog actionSheet(
            @NonNull Context context, @StringRes int titleRes,
            @StringRes int messageRes, @StringRes int cancelRes,
            @StringRes int button1TitleRes, @StringRes int button2TitleRes,
            CocoaDialogAction.OnClickListener cancelClickListener,
            CocoaDialogAction.OnClickListener button1ClickListener,
            CocoaDialogAction.OnClickListener button2ClickListener) {
        CocoaDialog.Builder builder = new CocoaDialog.Builder(context, CocoaDialogStyle.actionSheet);
        builder.setTitle(titleRes);
        builder.setMessage(messageRes);
        if (cancelRes != 0) {
            builder.addAction(new CocoaDialogAction(
                    context.getString(cancelRes),
                    CocoaDialogActionStyle.cancel,
                    cancelClickListener));
        }
        if (button1TitleRes != 0) {
            builder.addAction(new CocoaDialogAction(
                    context.getString(button1TitleRes),
                    CocoaDialogActionStyle.normal,
                    button1ClickListener
            ));
        }
        if (button2TitleRes != 0) {
            builder.addAction(new CocoaDialogAction(
                    context.getString(button2TitleRes),
                    CocoaDialogActionStyle.normal,
                    button2ClickListener
            ));
        }
        return builder.build();
    }

   /* public static CocoaDialog loading(Context context) {
        return context == null ? null : loading(context, false);
    }

    public static CocoaDialog loading(@NonNull Context context, boolean cancelable) {
        return new CocoaDialog.Builder(context, CocoaDialogStyle.custom)
                .setCustomContentView(LayoutInflater.from(context).inflate(R.layout.dialog_loading, null))
                .setCancelable(cancelable).build();
    }*/
}

